DevForce Help Reference
AddFilter(Type,Func<IQueryable,IQueryable>,Boolean) Method
Example 


Entity type
A Func that takes and returns an IQueryable{T}
Add a filter for an entity type to the collection.
Syntax
'Declaration
 
Public Overloads Sub AddFilter( _
   ByVal type As Type, _
   ByVal transformFunc As Func(Of IQueryable,IQueryable), _
   Optional ByVal canReplaceIfAlreadyExists As Boolean _
) 
'Usage
 
Dim instance As EntityQueryFilterCollection
Dim type As Type
Dim transformFunc As Func(Of IQueryable,IQueryable)
Dim canReplaceIfAlreadyExists As Boolean
 
instance.AddFilter(type, transformFunc, canReplaceIfAlreadyExists)

Parameters

type
Entity type
transformFunc
A Func that takes and returns an IQueryable{T}
canReplaceIfAlreadyExists
Exceptions
ExceptionDescription
System.ArgumentExceptionThrown if a filter for the entity type is already in the collection and the canReplaceIfAlreadyExists paremter is set to false
Remarks
The transformFunc, although it looks intimidating, is really a simple Where predicate which you're already familiar with when using query expression syntax. See the example for more information.
Example
public void FilteringSample() {
  // Query for all customers.  A filter will be applied prior to execution.
  var mgr = new DomainModelEntityManager();
  var list = mgr.Customers.ToList();
}

// Server-side implementation of EntityServerQueryInterceptor
public class EntityServerQueryManager : EntityServerQueryInterceptor {

  protected override bool FilterQuery()
    // Add filters
    QueryFilters.AddFilter<Customer>(q => q.Where(c => c.Country == "USA"));
    QueryFilters.AddFilter<Employee>(q => q.Where(e => e.Country == "USA"));
    return true;
	}
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

EntityQueryFilterCollection Class
EntityQueryFilterCollection Members
Overload List

Send Feedback